﻿using System;
using System.Collections.Generic;
using System.Linq;
using Gp.Scripts.Utils;
using QFramework;

namespace Gp.Scripts.Data.Equip {
    public static class WeaponPhraseMapper {
        private static readonly Dictionary<string, Type> DecoratorsMap;

        static WeaponPhraseMapper() {
            DecoratorsMap = new Dictionary<string, Type>();
            foreach (var t in typeof(WeaponPhraseMapper).Assembly.GetTargetType(typeof(WeaponPhraseAttribute),
                         baseClass: typeof(WeaponPhraseDecorator))) {
                var foo = t.GetAttribute<WeaponPhraseAttribute>();
                DecoratorsMap[foo.Phrase] = t;
            }
        }



        public static IEnumerable<string> DecoratorsNames => DecoratorsMap.Keys.ToList();
        
        
        
        
        public static WeaponPhraseDecorator Map(string phrase) {
            if (!DecoratorsMap.TryGetValue(phrase, out var t)) return null;
            return Activator.CreateInstance(t) as WeaponPhraseDecorator;
        }


        public static Type MapType(string phrase) {
            return !DecoratorsMap.TryGetValue(phrase, out var t) ? null : t;
        }
    }
}